package com.cool.collect.demo;

import java.sql.*;
public class CheckSQLSyntax {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            // 创建数据库连接
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/fds-local?characterEncoding=utf-8&useSSL=false&useUnicode=true&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8", "root", "1234");
            // 创建PreparedStatement对象
            pstmt = conn.prepareStatement("SELECT * FROM fds_goods_trade_detail WHERE s_id in ?");
            // 设置SQL语句参数
            pstmt.setString(1, "张三");
            // 执行SQL语句
            rs = pstmt.executeQuery();
            // 处理结果集
            while (rs.next()) {
                System.out.println(rs.getString("name") + "\t" + rs.getInt("age"));
            }
        } catch (SQLException e) {
            // 如果SQL语句有语法错误，则会抛出SQLException异常
            System.out.println(e.getMessage());
            e.printStackTrace();
        } finally {
            // 释放资源
            try { rs.close(); } catch (Exception e) { }
            try { pstmt.close(); } catch (Exception e) { }
            try { conn.close(); } catch (Exception e) { }
        }
    }
}